﻿using System;
using System.Collections.Generic;
using AutoMapper;
using CodeSaude.Application.Interfaces;
using CodeSaude.Application.ViewModels;
using CodeSaude.Domain.Entities;
using CodeSaude.Domain.Interfaces.Service;

namespace CodeSaude.Application.Services
{
    public class FuncaoApplicationService : BaseApplicationService,  IFuncaoApplicationService
    {
        private readonly IFuncaoService _funcaoService;

        public FuncaoApplicationService(IFuncaoService funcaoService)
        {
            _funcaoService = funcaoService;
        }

        //public ValidationApplicationResult Add(GrupoUsuarioViewModel GrupoUsuarioViewModel)
        //{
        //    var usuario = Mapper.Map<GrupoUsuarioViewModel, Usuario>(GrupoUsuarioViewModel);

        //    var result = _usuarioService.AdicionarUsuario(usuario);

        //    //if(result.IsValid)
        //        _usuarioService.SaveChanges();

        //    return Mapper.Map<ValidationResult, ValidationApplicationResult>(result);
        //}

        public void Add(FuncaoViewModel FuncaoViewModel)
        {
            var Funcao = Mapper.Map<FuncaoViewModel, Funcao>(FuncaoViewModel);

            BeginTransaction();
            _funcaoService.AdicionarFuncao(Funcao);
            Commit();
        }

        public FuncaoViewModel GetById(int id)
        {
            return Mapper.Map<FuncaoViewModel>(_funcaoService.GetById(id));
        }

        public IEnumerable<FuncaoViewModel> GetAll()
        {
            return Mapper.Map<IEnumerable<FuncaoViewModel>>(_funcaoService.GetAll());
        }

        public void Update(FuncaoViewModel FuncaoViewModel)
        {
            var Funcao = Mapper.Map<Funcao>(FuncaoViewModel);

            BeginTransaction();
            _funcaoService.Update(Funcao);
            Commit();
        }

        public void Remove(FuncaoViewModel FuncaoViewModel)
        {
            var user = _funcaoService.GetById(FuncaoViewModel.FuncaoId);
            BeginTransaction();
            _funcaoService.Remove(user);
            Commit();
        }

        public void Dispose()
        {
            _funcaoService.Dispose();
        }
    }
}
